package com.xigua._数学;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 给定一个 24 小时制（小时:分钟 "HH:MM"）的时间列表，找出列表中任意两个时间的最小时间差并以分钟数表示。
 * @date 2022/1/1822:05
 */
public class _539_最小时间差 {

    public static void main(String[] args) {
        List<String> timePoints = new ArrayList<>();
        timePoints.add("23:59");
        timePoints.add("00:00");
        System.out.println(findMinDifference(timePoints));

    }


    public static int findMinDifference(List<String> timePoints) {
        if (timePoints.size() > 1440) return 0;
        Collections.sort(timePoints);
        int ans = Integer.MAX_VALUE;
        int cur = timeToInt(timePoints.get(0));

        for (int i = 1; i < timePoints.size(); i++) {
            int minutes = timeToInt(timePoints.get(i));
            ans = Math.min(ans,minutes-cur);
            cur = minutes;
        }
        ans = Math.min(ans,timeToInt(timePoints.get(0))+1440-timeToInt(timePoints.get(timePoints.size()-1)));
       return ans;

    }
    public static int timeToInt(String time){
        return Character.getNumericValue(time.charAt(0))*60*10+
                Character.getNumericValue(time.charAt(1))*60+
                Character.getNumericValue(time.charAt(3))*10+
                Character.getNumericValue(time.charAt(4));
    }

}
